/*
 * Copyright (c) 2023 Cshoo Org. All Rights Reserved.
 */

package org.cshoo.tattoo.authorize.app;

import lombok.extern.slf4j.Slf4j;
import org.cshoo.tattoo.authorize.api.dto.AddMicroserviceReq;
import org.cshoo.tattoo.authorize.api.dto.UpdateMicroserviceReq;
import org.cshoo.tattoo.authorize.domain.po.Microservice;
import org.cshoo.tattoo.authorize.domain.service.MicroserviceService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 杨翼
 * @since 1.0
 */
@Service
@Slf4j
public class MicroserviceAppService {

    @Resource
    private MicroserviceService microserviceService;

    /**
     * 添加一个微服务
     *
     * @param addMicroserviceReq 微服务添加请求
     */
    public void addMicroservice(AddMicroserviceReq addMicroserviceReq) {
        Microservice microservice = new Microservice();
        BeanUtils.copyProperties(addMicroserviceReq, microservice);
        microserviceService.addMicroservice(microservice);
    }

    /**
     * 修改一个微服务
     *
     * @param updateMicroserviceReq 微服务修改对象
     */
    public void updateMicroservice(UpdateMicroserviceReq updateMicroserviceReq) {
        Microservice microservice = new Microservice();
        BeanUtils.copyProperties(updateMicroserviceReq, microservice);
        microserviceService.updateMicroservice(microservice);
    }

    /**
     * 删除一个微服务
     *
     * @param id id
     */
    public void deleteMicroservice(Long id) {
        microserviceService.deleteMicroservice(id);
    }

    /**
     * 查询所有微服务
     *
     * @return 微服务
     */
    public List<Microservice> findAllMicroservice() {
        return microserviceService.findAllMicroservice();
    }
}
